package  com.pcbly.web.business.publicinfo;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.publicinfo.SuggestDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.publicinfo.SuggestBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class SuggestServiceImp extends BaseServiceImp<SuggestBean> implements SuggestService {
	 public SuggestServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private SuggestDao suggestDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setSuggestDao(SuggestDao suggestDao) {
		this.suggestDao = suggestDao;
	}
	
	@Override
	public SuggestBean getSuggestBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return suggestDao.get(SuggestBean.class,id);
	}
	
	@Override
	public void removeSuggestBeanById(String id) throws Exception{
		suggestDao.removeSuggestBeanById(id);
	}
	
	@Override
	public void removeSuggestBeanByIds(String ids) throws Exception{
		suggestDao.removeSuggestBeanByIds(ids);
	}
	
	
	@Override
	public SuggestBean saveSuggestBean(SuggestBean publicinfo) throws Exception{
		return suggestDao.saveSuggestBean(publicinfo);
	}
	
	@Override
	public SuggestBean updateSuggestBean(SuggestBean publicinfo) throws Exception{
		suggestDao.saveObject( publicinfo);
		return publicinfo;
	}
	public Page<SuggestBean>  findSuggestBeanByCond(SuggestBean bean,
			Page<SuggestBean> page, String orderByName, boolean asc)
			throws Exception{
		return suggestDao.findSuggestBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findSuggestBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findSuggestBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = suggestDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findSuggestBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = suggestDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveSuggestBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		suggestDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasSuggestBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return suggestDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
